using System;
using System.Threading.Tasks;
using JlPay.Sdk.Core;
using JlPay.Sdk.Services.Openmerch.Change;
using JlPay.Sdk.Models.Openmerch.Change;

namespace JlPay.Sdk.Examples.Openmerch.Change.SignInfoModify
{
    /// <summary>
    /// 签约信息修改独立示例程序
    /// </summary>
    public class SignInfoModifyDemo
    {
        /// <summary>
        /// 主程序入口
        /// </summary>
        /// <param name="args">命令行参数</param>
        /// <returns>任务</returns>
        public static async Task Main(string[] args)
        {
            Console.WriteLine("==========================================");
            Console.WriteLine("===== 签约信息修改独立示例程序 =====");
            Console.WriteLine("==========================================");
            Console.WriteLine();

            await SignInfoModifyDemoAsync();

            Console.WriteLine("==========================================");
            Console.WriteLine("===== 示例运行完毕 =====");
            Console.WriteLine("==========================================");
        }

        /// <summary>
        /// 创建配置对象
        /// </summary>
        /// <returns>配置对象</returns>
        private static Config CreateConfig()
        {
            return DemoConfig.CreateConfigWithCrypto();
        }

        /// <summary>
        /// 构建签约信息修改请求
        /// </summary>
        /// <returns>请求对象</returns>
        private static SignInfoModifyRequest BuildSignInfoModifyRequest()
        {
            var request = new SignInfoModifyRequest
            {
                OrgNo = "50720711",
                MerchNo = "849584358140108",
                ApplyId = "b8659ea518d14c99b78b5000a08106A",
                SignMode = "1",
                AgreementPic = "https://example.com/agreement.jpg",
                LegalPersonPhone = "13800138000",
                DelegateePhone = "13800138001"
            };

            return request;
        }

        /// <summary>
        /// 签约信息修改示例
        /// </summary>
        public static async Task SignInfoModifyDemoAsync()
        {
            Console.WriteLine("开始执行签约信息修改示例");
            
            try
            {
                // 创建配置对象和变更服务
                var config = CreateConfig();
                var changeService = new ChangeService(config);
                
                // 创建签约信息修改请求
                var request = BuildSignInfoModifyRequest();
                
                // 发送请求
                var response = await changeService.ModifySignInfoAsync(request);
                
                // 处理响应结果
                response.HandleResponse("签约信息修改", config);
            }
            catch (Exception ex)
            {
                var config = CreateConfig();
                var response = new SignInfoModifyResponse();
                response.HandleResponseWithException("签约信息修改", config, ex);
            }
            
            Console.WriteLine("签约信息修改示例执行完毕");
        }
    }
} 